#ifndef CONNECTION_H
#define CONNECTION_H

#include "../widget/wprogressbar.h"
#include "../core/filehandler.h"

#include <QSqlDatabase>
#include <QString>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>

/*
 * declare DB driver and filename.
 */
static const QString dbDriverStr = "QSQLITE";
static const QString dbFileNameStr = "wouaf.s3db";
static const int PBAR_MAX_STEPS = 7;

/*
 * String messages.
 */
static QString dbDriverNotExistStr =
       QObject::tr("Database driver is not available");
static QString dbCannotOpenStr =
       QObject::tr("Database cannot open");
static QString dbConnectionOk =
        QObject::tr("Database open");
static QString dbDisconnectStr =
        QObject::tr("Database close");
static QString dbQueryStr =
        QObject::tr("Database exec query : ");
static QString dbFailedStr =
        QObject::tr("The query failed to exec");
static QString dbCreateDatabase =
        QObject::tr("Creating database");

class Connection
{      
private:
    static Connection * instance;

protected:
    Connection();
    QSqlDatabase db;
    FileHandler dbFile;
    bool createTable(WProgressBar *progress, const QString &cmd);
    bool insertUnknow(WProgressBar *progress, const QString & cmd);

public:
    static Connection * getInstance();
    bool dbConnect();
    bool isConnected();
    bool dbDisconnect();
    bool isDbExist();
    bool dbRemove();
    bool dbCreateInstance();

    ~Connection();
};

#endif // CONNECTION_H
